import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'
import { routerBreadcrumb } from '@/utils/local-data';
import ArticleList from "@/components/ArticleList.vue";
import ArticleDetail from "@/components/ArticleDetail.vue";
import HomePage from "@/components/HomePage.vue";

import Index from '@/components/Index.vue';
import ClassList from '../components/ClassList.vue';

import store from '@/store';

Vue.use(Router)

const router = new Router({
  mode: "history",
  routes: [
    {
      path: "/",
      name: "root",
      component: Index,
      redirect: "/show",
      children: [
        {
          path: "/show",
          name: "show",
          component: HomePage
        },
        {
          path: "/articleList",
          name: "articleList",
          component: ArticleList,
          meta: {
            list: routerBreadcrumb.articleList.list
          }
        },
        {
          path: "/articleDetail",
          name: "articleDetail",
          component: ArticleDetail,
          meta: {
            list: routerBreadcrumb.articleDetail.list,
            back: routerBreadcrumb.articleDetail.back
          }
        },
        // 首页
        {
          path: "/indexList",
          name: "indexList",
          component: HomePage,
          meta: {
            list: routerBreadcrumb.indexList.list
          }
        },
        // 学生列表
        {
          path: "/classlist",
          name: "classlist",
          component: ClassList,
        }
      ]
    }
    // {
    //   path: "/articleList",
    //   name: "articleList",
    //   component: ArticleList,
    //   meta: {
    //     list: routerBreadcrumb.articleList.list
    //   }
    // },
    // {
    //   path: "/articleDetail",
    //   name: "articleDetail",
    //   component: ArticleDetail,
    //   meta: {
    //     list: routerBreadcrumb.articleDetail.list
    //   }
    // },
    // // 首页
    // {
    //   path: "/indexList",
    //   name: "indexList",
    //   component: HomePage,
    //   meta: {
    //     list: routerBreadcrumb.indexList.list
    //   }
    // }
  ]
});

router.beforeEach((to, from, next) => {
  if (to.meta.list) {
    let list = to.meta.list;
    store.commit("changeBreadcrumb", { list });
  }
  if (to.meta.back) {
    let back = to.meta.back;
    store.commit("changeBack", { back });
  }
  next();
});

export default router;
